IF EXISTS (SELECT name from [msdb].[dbo].[syscollector_collection_sets_internal] where name = 'ssas_monitoring_core') EXEC [msdb].[dbo].[sp_syscollector_delete_collection_set] @name='ssas_monitoring_core'--@collection_set_id=37
GO
Begin Transaction
Begin Try
Declare @collection_set_id_1 int
Declare @collection_set_uid_2 uniqueidentifier
EXEC [msdb].[dbo].[sp_syscollector_create_collection_set] @name=N'SSAS_Monitoring_Core'
, @collection_mode=0, @description=N'Collects SQL Server 2008 Analysis Services querying counters'
, @logging_level=0
, @days_until_expiration=0
, @schedule_name=N'CollectorSchedule_Every_15min'
, @collection_set_id=@collection_set_id_1 OUTPUT
, @collection_set_uid=@collection_set_uid_2 OUTPUT
Select @collection_set_id_1, @collection_set_uid_2

Declare @collector_type_uid_3 uniqueidentifier
Select @collector_type_uid_3 = collector_type_uid From [msdb].[dbo].[syscollector_collector_types] Where name = N'Performance Counters Collector Type';
Declare @collection_item_id_4 int
EXEC [msdb].[dbo].[sp_syscollector_create_collection_item] @name=N'SSAS_Monitoring_Core', 
@parameters=N'<ns:PerformanceCountersCollector xmlns:ns="DataCollectorType">
<PerformanceCounters Objects="$(PerfCounterPrefix):Cache" Counters="Current KB" />
<PerformanceCounters Objects="$(PerfCounterPrefix):Cache" Counters="Direct hits/sec" />
<PerformanceCounters Objects="$(PerfCounterPrefix):Cache" Counters="Evictions/sec" />
<PerformanceCounters Objects="$(PerfCounterPrefix):Cache" Counters="Inserts/sec" />
<PerformanceCounters Objects="$(PerfCounterPrefix):Cache" Counters="Lookups/sec" />
<PerformanceCounters Objects="$(PerfCounterPrefix):Cache" Counters="Misses/sec" />
<PerformanceCounters Objects="$(PerfCounterPrefix):Connection" Counters="Current connections" />
<PerformanceCounters Objects="$(PerfCounterPrefix):Connection" Counters="Current user sessions" />
<PerformanceCounters Objects="$(PerfCounterPrefix):Connection" Counters="Failures/sec" />
<PerformanceCounters Objects="$(PerfCounterPrefix):Connection" Counters="Requests/sec" />
<PerformanceCounters Objects="$(PerfCounterPrefix):Locks" Counters="Current lock waits" />
<PerformanceCounters Objects="$(PerfCounterPrefix):Locks" Counters="Lock grants/sec" />
<PerformanceCounters Objects="$(PerfCounterPrefix):Locks" Counters="Lock waits/sec" />
<PerformanceCounters Objects="$(PerfCounterPrefix):MDX" Counters="Current number of cached evaluation nodes" />
<PerformanceCounters Objects="$(PerfCounterPrefix):MDX" Counters="Current number of evaluation nodes" />
<PerformanceCounters Objects="$(PerfCounterPrefix):MDX" Counters="Number of bulk-mode evaluation nodes" />
<PerformanceCounters Objects="$(PerfCounterPrefix):MDX" Counters="Number of cached bulk-mode evaluation nodes" />
<PerformanceCounters Objects="$(PerfCounterPrefix):MDX" Counters="Number of cached ''other'' evaluation nodes" />
<PerformanceCounters Objects="$(PerfCounterPrefix):MDX" Counters="Number of cached Storage Engine evaluation nodes" />
<PerformanceCounters Objects="$(PerfCounterPrefix):MDX" Counters="Number of calculation covers" />
<PerformanceCounters Objects="$(PerfCounterPrefix):MDX" Counters="Number of cell-by-cell evaluation nodes" />
<PerformanceCounters Objects="$(PerfCounterPrefix):MDX" Counters="Number of cell-by-cell hits in the cache of evaluation nodes" />
<PerformanceCounters Objects="$(PerfCounterPrefix):MDX" Counters="Number of cell-by-cell misses in the cache of evaluation nodes" />
<PerformanceCounters Objects="$(PerfCounterPrefix):MDX" Counters="Number of evaluation nodes that covered a single cell" />
<PerformanceCounters Objects="$(PerfCounterPrefix):MDX" Counters="Number of evaluation nodes with calculations at the same granularity" />
<PerformanceCounters Objects="$(PerfCounterPrefix):MDX" Counters="Number of evictions of evaluation nodes" />
<PerformanceCounters Objects="$(PerfCounterPrefix):MDX" Counters="Number of hash index hits in the cache of evaluation nodes" />
<PerformanceCounters Objects="$(PerfCounterPrefix):MDX" Counters="Number of Storage Engine evaluation nodes" />
<PerformanceCounters Objects="$(PerfCounterPrefix):MDX" Counters="Number of subcube hits in the cache of evaluation nodes" />
<PerformanceCounters Objects="$(PerfCounterPrefix):MDX" Counters="Number of subcube misses in the cache of evaluation nodes" />
<PerformanceCounters Objects="$(PerfCounterPrefix):Memory" Counters="Cleaner Memory nonshrinkable KB" />
<PerformanceCounters Objects="$(PerfCounterPrefix):Memory" Counters="Cleaner Memory shrinkable KB" />
<PerformanceCounters Objects="$(PerfCounterPrefix):Memory" Counters="Cleaner Memory shrunk KB/sec" />
<PerformanceCounters Objects="$(PerfCounterPrefix):Memory" Counters="Filestore IO Errors" />
<PerformanceCounters Objects="$(PerfCounterPrefix):Memory" Counters="Filestore IO Errors/sec" />
<PerformanceCounters Objects="$(PerfCounterPrefix):Memory" Counters="Filestore KB Reads/sec" />
<PerformanceCounters Objects="$(PerfCounterPrefix):Memory" Counters="Filestore KB Write/sec" />
<PerformanceCounters Objects="$(PerfCounterPrefix):Memory" Counters="Filestore Reads/sec" />
<PerformanceCounters Objects="$(PerfCounterPrefix):Memory" Counters="Filestore Writes/sec" />
<PerformanceCounters Objects="$(PerfCounterPrefix):Memory" Counters="Memory Limit High KB" />
<PerformanceCounters Objects="$(PerfCounterPrefix):Memory" Counters="Memory Limit Low KB" />
<PerformanceCounters Objects="$(PerfCounterPrefix):Memory" Counters="Memory Usage KB" />
<PerformanceCounters Objects="$(PerfCounterPrefix):Proc Aggregations" Counters="Current partitions" />
<PerformanceCounters Objects="$(PerfCounterPrefix):Proc Aggregations" Counters="Rows created/sec" />
<PerformanceCounters Objects="$(PerfCounterPrefix):Proc Aggregations" Counters="Temp file bytes written/sec" />
<PerformanceCounters Objects="$(PerfCounterPrefix):Proc Indexes" Counters="Current partitions" />
<PerformanceCounters Objects="$(PerfCounterPrefix):Proc Indexes" Counters="Rows/sec" />
<PerformanceCounters Objects="$(PerfCounterPrefix):Processing" Counters="Rows read/sec" />
<PerformanceCounters Objects="$(PerfCounterPrefix):Processing" Counters="Rows written/sec" />
<PerformanceCounters Objects="$(PerfCounterPrefix):Storage Engine Query" Counters="Aggregation hits/sec" />
<PerformanceCounters Objects="$(PerfCounterPrefix):Storage Engine Query" Counters="Aggregation Lookups/sec" />
<PerformanceCounters Objects="$(PerfCounterPrefix):Storage Engine Query" Counters="Avg time/query" />
<PerformanceCounters Objects="$(PerfCounterPrefix):Storage Engine Query" Counters="Bytes sent/sec" />
<PerformanceCounters Objects="$(PerfCounterPrefix):Storage Engine Query" Counters="Calculation cache hits/sec" />
<PerformanceCounters Objects="$(PerfCounterPrefix):Storage Engine Query" Counters="Calculation cache lookups/sec" />
<PerformanceCounters Objects="$(PerfCounterPrefix):Storage Engine Query" Counters="Data bytes/sec" />
<PerformanceCounters Objects="$(PerfCounterPrefix):Storage Engine Query" Counters="Data reads/sec" />
<PerformanceCounters Objects="$(PerfCounterPrefix):Storage Engine Query" Counters="Flat cache hits/sec" />
<PerformanceCounters Objects="$(PerfCounterPrefix):Storage Engine Query" Counters="Flat cache lookups/sec" />
<PerformanceCounters Objects="$(PerfCounterPrefix):Storage Engine Query" Counters="Map bytes/sec" />
<PerformanceCounters Objects="$(PerfCounterPrefix):Storage Engine Query" Counters="Map reads/sec" />
<PerformanceCounters Objects="$(PerfCounterPrefix):Storage Engine Query" Counters="Measure group cache hits/sec" />
<PerformanceCounters Objects="$(PerfCounterPrefix):Storage Engine Query" Counters="Measure group cache lookups/sec" />
<PerformanceCounters Objects="$(PerfCounterPrefix):Storage Engine Query" Counters="Measure group queries/sec" />
<PerformanceCounters Objects="$(PerfCounterPrefix):Storage Engine Query" Counters="Network round trips/sec" />
<PerformanceCounters Objects="$(PerfCounterPrefix):Storage Engine Query" Counters="Persisted cache hits/sec" />
<PerformanceCounters Objects="$(PerfCounterPrefix):Storage Engine Query" Counters="Persisted cache lookups/sec" />
<PerformanceCounters Objects="$(PerfCounterPrefix):Storage Engine Query" Counters="Queries answered/sec" />
<PerformanceCounters Objects="$(PerfCounterPrefix):Storage Engine Query" Counters="Queries from cache direct/sec" />
<PerformanceCounters Objects="$(PerfCounterPrefix):Storage Engine Query" Counters="Queries from cache filtered/sec" />
<PerformanceCounters Objects="$(PerfCounterPrefix):Storage Engine Query" Counters="Queries from file/sec" />
<PerformanceCounters Objects="$(PerfCounterPrefix):Storage Engine Query" Counters="Rows sent/sec" />
<PerformanceCounters Objects="$(PerfCounterPrefix):Threads" Counters="Processing pool busy threads" />
<PerformanceCounters Objects="$(PerfCounterPrefix):Threads" Counters="Processing pool idle threads" />
<PerformanceCounters Objects="$(PerfCounterPrefix):Threads" Counters="Processing pool job queue length" />
<PerformanceCounters Objects="$(PerfCounterPrefix):Threads" Counters="Processing pool job rate" />
<PerformanceCounters Objects="$(PerfCounterPrefix):Threads" Counters="Query pool busy threads" />
<PerformanceCounters Objects="$(PerfCounterPrefix):Threads" Counters="Query pool idle threads" />
<PerformanceCounters Objects="$(PerfCounterPrefix):Threads" Counters="Query pool job queue length" />
<PerformanceCounters Objects="$(PerfCounterPrefix):Threads" Counters="Query pool job rate" />

<PerformanceCounters Objects="Process" Counters="*" Instances="msmdsrv" />
<PerformanceCounters Objects="Process" Counters="*" Instances="_Total" />
<PerformanceCounters Objects="Process" Counters="Thread Count" Instances="*" />
<PerformanceCounters Objects="Process" Counters="% Processor Time" Instances="*" />
<PerformanceCounters Objects="Process" Counters="IO Read Bytes/sec" Instances="*" />
<PerformanceCounters Objects="Process" Counters="IO Write Bytes/sec" Instances="*" />
<PerformanceCounters Objects="Process" Counters="Private Bytes" Instances="*" />
<PerformanceCounters Objects="Process" Counters="Working Set" Instances="*" />

<PerformanceCounters Objects="Memory" Counters="% Committed Bytes In Use" />
<PerformanceCounters Objects="Memory" Counters="Available Bytes" />
<PerformanceCounters Objects="Memory" Counters="Cache Bytes" />
<PerformanceCounters Objects="Memory" Counters="Cache Faults/sec" />
<PerformanceCounters Objects="Memory" Counters="Committed Bytes" />
<PerformanceCounters Objects="Memory" Counters="Free &amp; Zero Page List Bytes" />
<PerformanceCounters Objects="Memory" Counters="Modified Page List Bytes" />
<PerformanceCounters Objects="Memory" Counters="Pages/sec" />
<PerformanceCounters Objects="Memory" Counters="Page Reads/sec" />
<PerformanceCounters Objects="Memory" Counters="Page Write/sec" />
<PerformanceCounters Objects="Memory" Counters="Page Faults/sec" />
<PerformanceCounters Objects="Memory" Counters="Pool Nonpaged Bytes" />
<PerformanceCounters Objects="Memory" Counters="Pool Paged Bytes" />
<PerformanceCounters Objects="Memory" Counters="Standby Cache Core Bytes" />
<PerformanceCounters Objects="Memory" Counters="Standby Cache Normal Priority Bytes" />
<PerformanceCounters Objects="Memory" Counters="Standby Cache Reserve Bytes" />
<PerformanceCounters Objects="Memory" Counters="Pool Paged Bytes" />
<PerformanceCounters Objects="Memory" Counters="Write Copies/sec" />

<PerformanceCounters Objects="Processor" Counters="% Processor Time" Instances="*" />
<PerformanceCounters Objects="Processor" Counters="% User Time" Instances="*" />
<PerformanceCounters Objects="Processor" Counters="% Privileged Time" Instances="*" />

<PerformanceCounters Objects="Server Work Queues" Counters="Queue Length" Instances="*" />

<PerformanceCounters Objects="LogicalDisk" Counters="% Disk Time" Instances="*" />
<PerformanceCounters Objects="LogicalDisk" Counters="Avg. Disk Queue Length" Instances="*" />
<PerformanceCounters Objects="LogicalDisk" Counters="Avg. Disk Read Queue Length" Instances="*" />
<PerformanceCounters Objects="LogicalDisk" Counters="Avg. Disk Write Queue Length" Instances="*" />
<PerformanceCounters Objects="LogicalDisk" Counters="Avg. Disk sec/Read" Instances="*" />
<PerformanceCounters Objects="LogicalDisk" Counters="Avg. Disk sec/Write" Instances="*" />
<PerformanceCounters Objects="LogicalDisk" Counters="Avg. Disk sec/Transfer" Instances="*" />
<PerformanceCounters Objects="LogicalDisk" Counters="Disk Reads/sec" Instances="*" />
<PerformanceCounters Objects="LogicalDisk" Counters="Disk Bytes/sec" Instances="*" />
<PerformanceCounters Objects="LogicalDisk" Counters="Disk Writes/sec" Instances="*" />
<PerformanceCounters Objects="LogicalDisk" Counters="Split IO/sec" Instances="*" />

<PerformanceCounters Objects="System" Counters="Processor Queue Length" />
<PerformanceCounters Objects="System" Counters="File Read Operations/sec" />
<PerformanceCounters Objects="System" Counters="File Write Operations/sec" />
<PerformanceCounters Objects="System" Counters="File Control Operations/sec" />
<PerformanceCounters Objects="System" Counters="File Read Bytes/sec" />
<PerformanceCounters Objects="System" Counters="File Write Bytes/sec" />
<PerformanceCounters Objects="System" Counters="File Control Bytes/sec" />

<PerformanceCounters Objects="Network Interface" Counters="Bytes Total/sec" Instances="*" />
<PerformanceCounters Objects="Network Interface" Counters="Output Queue Length" Instances="*" />



</ns:PerformanceCountersCollector>', @collection_item_id=@collection_item_id_4 OUTPUT, @frequency=$(ReadSSASCoreJobSchedule), @collection_set_id=@collection_set_id_1, @collector_type_uid=@collector_type_uid_3
Select @collection_item_id_4

Commit Transaction;
End Try
Begin Catch
Rollback Transaction;
DECLARE @ErrorMessage NVARCHAR(4000);
DECLARE @ErrorSeverity INT;
DECLARE @ErrorState INT;
DECLARE @ErrorNumber INT;
DECLARE @ErrorLine INT;
DECLARE @ErrorProcedure NVARCHAR(200);
SELECT @ErrorLine = ERROR_LINE(),
       @ErrorSeverity = ERROR_SEVERITY(),
       @ErrorState = ERROR_STATE(),
       @ErrorNumber = ERROR_NUMBER(),
       @ErrorMessage = ERROR_MESSAGE(),
       @ErrorProcedure = ISNULL(ERROR_PROCEDURE(), '-');
RAISERROR (14684, @ErrorSeverity, 1 , @ErrorNumber, @ErrorSeverity, @ErrorState, @ErrorProcedure, @ErrorLine, @ErrorMessage);

End Catch;

GO


